<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - bit_stream_kernel_c.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2003  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_BIT_STREAM_KERNEl_C_
<font color='#0000FF'>#define</font> DLIB_BIT_STREAM_KERNEl_C_

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='bit_stream_kernel_abstract.h.html'>bit_stream_kernel_abstract.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../algs.h.html'>../algs.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../assert.h.html'>../assert.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>iosfwd<font color='#5555FF'>&gt;</font>

<font color='#0000FF'>namespace</font> dlib
<b>{</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> bit_stream_base <font color='#009900'>// implements bit_stream/bit_stream_kernel_abstract.h
</font>        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>class</font> <b><a name='bit_stream_kernel_c'></a>bit_stream_kernel_c</b> : <font color='#0000FF'>public</font> bit_stream_base
    <b>{</b>
    <font color='#0000FF'>public</font>:


        <font color='#0000FF'><u>void</u></font> <b><a name='set_input_stream'></a>set_input_stream</b> <font face='Lucida Console'>(</font>
            std::istream<font color='#5555FF'>&amp;</font> is
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_output_stream'></a>set_output_stream</b> <font face='Lucida Console'>(</font>
            std::ostream<font color='#5555FF'>&amp;</font> os
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='close'></a>close</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='write'></a>write</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>int</u></font> bit
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>bool</u></font> <b><a name='read'></a>read</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>int</u></font><font color='#5555FF'>&amp;</font> bit
        <font face='Lucida Console'>)</font>;

    <b>}</b>;

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> bit_stream_base
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='swap'></a>swap</b> <font face='Lucida Console'>(</font>
        bit_stream_kernel_c<font color='#5555FF'>&lt;</font>bit_stream_base<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> a, 
        bit_stream_kernel_c<font color='#5555FF'>&lt;</font>bit_stream_base<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> b
    <font face='Lucida Console'>)</font> <b>{</b> a.<font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>b<font face='Lucida Console'>)</font>; <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// member function definitions
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> bit_stream_base
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> bit_stream_kernel_c<font color='#5555FF'>&lt;</font>bit_stream_base<font color='#5555FF'>&gt;</font>:: 
    <b><a name='set_input_stream'></a>set_input_stream</b> <font face='Lucida Console'>(</font>
        std::istream<font color='#5555FF'>&amp;</font> is
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font> <font color='#0000FF'>this</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>is_in_write_mode</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font> <font color='#0000FF'>this</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>is_in_read_mode</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font face='Lucida Console'>)</font>, 
            "<font color='#CC0000'>\tvoid bit_stream::set_intput_stream</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tbit_stream must not be in write or read mode</font>" 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
            <font face='Lucida Console'>)</font>;

        <font color='#009900'>// call the real function
</font>        bit_stream_base::<font color='#BB00BB'>set_input_stream</font><font face='Lucida Console'>(</font>is<font face='Lucida Console'>)</font>;

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> bit_stream_base
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> bit_stream_kernel_c<font color='#5555FF'>&lt;</font>bit_stream_base<font color='#5555FF'>&gt;</font>:: 
    <b><a name='set_output_stream'></a>set_output_stream</b> <font face='Lucida Console'>(</font>
        std::ostream<font color='#5555FF'>&amp;</font> os
    <font face='Lucida Console'>)</font>
    <b>{</b>

        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font> <font color='#0000FF'>this</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>is_in_write_mode</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font> <font color='#0000FF'>this</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>is_in_read_mode</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font face='Lucida Console'>)</font>, 
            "<font color='#CC0000'>\tvoid bit_stream::set_output_stream</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tbit_stream must not be in write or read mode</font>" 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
            <font face='Lucida Console'>)</font>;

        <font color='#009900'>// call the real function
</font>        bit_stream_base::<font color='#BB00BB'>set_output_stream</font><font face='Lucida Console'>(</font>os<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> bit_stream_base
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> bit_stream_kernel_c<font color='#5555FF'>&lt;</font>bit_stream_base<font color='#5555FF'>&gt;</font>:: 
    <b><a name='close'></a>close</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>

        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font> <font color='#0000FF'>this</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>is_in_write_mode</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>true</font> <font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> <font face='Lucida Console'>(</font> <font color='#0000FF'>this</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>is_in_read_mode</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>true</font> <font face='Lucida Console'>)</font>, 
            "<font color='#CC0000'>\tvoid bit_stream::close</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tyou can't close a bit_stream that isn't open</font>" 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
            <font face='Lucida Console'>)</font>;

        <font color='#009900'>// call the real function
</font>        bit_stream_base::<font color='#BB00BB'>close</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> bit_stream_base
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> bit_stream_kernel_c<font color='#5555FF'>&lt;</font>bit_stream_base<font color='#5555FF'>&gt;</font>:: 
    <b><a name='write'></a>write</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>int</u></font> bit
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font> <font color='#0000FF'>this</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>is_in_write_mode</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>true</font> <font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font> bit <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> bit <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font> <font face='Lucida Console'>)</font>, 
            "<font color='#CC0000'>\tvoid bit_stream::write</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthe bit stream bust be in write mode and bit must be either 1 or 0</font>" 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tis_in_write_mode() == </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>is_in_write_mode</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tbit == </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> bit
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
            <font face='Lucida Console'>)</font>;

        <font color='#009900'>// call the real function
</font>        bit_stream_base::<font color='#BB00BB'>write</font><font face='Lucida Console'>(</font>bit<font face='Lucida Console'>)</font>;

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> bit_stream_base
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>bool</u></font> bit_stream_kernel_c<font color='#5555FF'>&lt;</font>bit_stream_base<font color='#5555FF'>&gt;</font>:: 
    <b><a name='read'></a>read</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>int</u></font><font color='#5555FF'>&amp;</font> bit
    <font face='Lucida Console'>)</font>
    <b>{</b>

        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font> <font color='#0000FF'>this</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>is_in_read_mode</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>true</font> <font face='Lucida Console'>)</font>, 
            "<font color='#CC0000'>\tbool bit_stream::read</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tyou can't read from a bit_stream that isn't in read mode</font>" 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
            <font face='Lucida Console'>)</font>;

        <font color='#009900'>// call the real function
</font>        <font color='#0000FF'>return</font> bit_stream_base::<font color='#BB00BB'>read</font><font face='Lucida Console'>(</font>bit<font face='Lucida Console'>)</font>;

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_BIT_STREAM_KERNEl_C_
</font>

</pre></body></html>